﻿#region Header
/*
 * name：Unity
 * author：Kain
 * date：11/25/2010 4:05:00 PM
 *********************************************
 * History:
 * $Header$
 * $History$
 */
#endregion

#region imported namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cherry.Agile.ServiceModel.Interceptor;
using Cherry.Agile.Core.Instrumentation;
using Cherry.Agile.Core;
using Microsoft.Practices.Unity;
#endregion

namespace Cherry.Agile.ServiceModel
{
	public static class Unity
	{
        public const string NAMESPACE = "http://www.szxys.cn/remp2";

        public static readonly string ADMIN_SERVICE_NAMESPACE = NAMESPACE + "/admin";

        internal static bool GetIsBidirectionalSet(Type type, bool isBidirectional)
        {
            if (isBidirectional)
                return isBidirectional;
            var atrs = type.GetCustomAttributes(typeof(ServiceInterceptorAttribute), true);
            if (atrs.Length > 0)
                return isBidirectional || (atrs[0] as ServiceInterceptorAttribute).IsBidirectional;
            return isBidirectional;
        }

        internal static IClientInstrumentationProvider GetClientInstrumentationProvider() {
            string instanceName = Cherry.Agile.Configuration.AgileConfiguration.Current.ApplicationSection.Name;
            if (string.IsNullOrEmpty(instanceName))
                instanceName = "Remp Web";
            if (Container.Current.IsRegistered<IClientInstrumentationProvider>())
                return Container.Current.Resolve<IClientInstrumentationProvider>(new ParameterOverride("name", instanceName));
            return null;

        }
	}
}
